#pragma once
#include<QNetworkAccessManager>
#include<QNetworkRequest>
#include<QNetworkReply>
#include<QEventLoop>
#include<QString>
#include<QJsonObject>
#include<QByteArray>
#include<QSettings>
#include<QTimer>
#include<QVersionNumber>
#include<singleton.h>
#include<enum_file.h>

#define OVERSEAS(X)                             (QString(X) + QString("_international"))

#define ENVIRONMENT_GROUP                       "environment"
#define KEY_VERSION                             "version"

#define CLOUD_API_TEST_GROUP                    "cloud_api_test"
#define CLOUD_API_PROD_GROUP                    "cloud_api_prod"

#define GA_REPORTER                             "ga_reporter"
#define GA_REGION                               "ga_region"
#define CLOUD_API                               "cloud_api"
#define QCODE_ANDROID                           "qrcode_android"
#define QCODE_IOS                               "qrcode_ios"
#define PRIVACY                                 "privacy"
#define USERAGREEMENT                           "useragreement"
#define AUTO_UPDATE                             "auto_update"
#define AUTO_UPDATE_MAC                         "auto_update_mac"
#define ABOUT_US                                "about_us"

class CloudConfig : public QObject
{
    Q_OBJECT
public:
    explicit CloudConfig();
    ~CloudConfig();

    QVariant cloudApi(CommonEnum::CloudUrl type);
    void initCloudData();

private slots:
    void networkFinisheded();

private:
    void readConfig();
    template<typename T>
    void readConfig(QSettings* setting, T& map, T& mapOverseas, \
        const QString& groupName, const QString& key);

    QSettings *m_setting = nullptr;
    QString m_groupName;
    std::map<QString, std::map<QString, QVariant>> m_cloudMap;
    std::map<QString, std::map<QString, QVariant>> m_cloudMapOverseas;
    QVersionNumber m_curVersion;         // 环境的版本
    QNetworkAccessManager m_networkAccessManager;
    QNetworkReply *m_reply = nullptr;

};

